﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MessageWorkflow;
using MessageWorkflow.Handler;

namespace SimpleConsoleExamples.Examples
{
    class OneWayExample : IExample
    {    
        public void Run()
        {
            WorkflowChannel channel = new WorkflowChannel();

            var handler1 = WorkflowHandlerFactory.FromLambda<string>(x => Console.WriteLine("InnerHandler 1 received: {0}", x));
            var handler2 = WorkflowHandlerFactory.FromLambda<string>(x => Console.WriteLine("InnerHandler 2 received: {0}", x));
            var handler3 = WorkflowHandlerFactory.FromLambda<string>(x => Console.WriteLine("InnerHandler 3 received: {0}", x));
            var handler4 = WorkflowHandlerFactory.FromLambda<string>(x => Console.WriteLine("InnerHandler 4 received: {0}", x));

            channel.Subscribe(new WorkflowHandlerConfiguration(handler1)
            {
                Successors = new[]
                {
                    new WorkflowHandlerConfiguration(handler2)
                    {
                        Successors = new[]
                        {
                            new WorkflowHandlerConfiguration(handler4)
                        }
                    },
                    new WorkflowHandlerConfiguration(handler3)
                }
            });

            channel.Dispatch("test");
        }
    }
}
